package com.example;

import com.example.vault.entity.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.vault.core.VaultOperations;
import org.springframework.vault.support.VaultResponseSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@SpringBootApplication
public class SpringbootVaultApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootVaultApplication.class, args);
    }

    @Autowired
    VaultOperations vaultOperations;

    @RequestMapping("/hello")
    public void hello() {

        List<String> list = vaultOperations.list("kv/vault");
        System.out.println("查询列表结果： " + list);


        Person person = new Person(1, "test001", "test001", "test001");
        vaultOperations.write("secret/myapplication/user/3128", person);
        System.out.println("写入结果： " + person);

        VaultResponseSupport<Person> responseSupport = vaultOperations.read("secret/myapplication/user/3128", Person.class);
        responseSupport.getData();
        System.out.println("查询结果： " + responseSupport);
    }
}
